<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <div class="row h-home-path">
          <div class="col-md-12">
            <ol class="breadcrumb">
              <li><i class="fa fa-home"></i>&nbsp;&nbsp;所在位置</li>
              <li>首页</li>
              <li class="active">编辑用户信息</li>
            </ol>
          </div>
        </div>
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" id="return-btn" onclick="returnIndex()"><i class="fa fa-mail-reply">&nbsp;&nbsp;</i>返回
              </button>
              <button class="btn btn-info" id="save" onclick="UserMgr.submitForm()" type="button"><i class="fa fa-save">&nbsp;&nbsp;</i>保存
              </button>
            </div>
          </form>
        </div>

        <div class="form-horizontal  h-form-warp">
          <div class="h-msg-title h-table-header">
            <strong>用户信息</strong>
          </div>
          <form action="/securityUser/saveUser" class="form-horizontal" id="userForm" method="post" role="form">
            <input id="operation" name="operation" type="hidden" value="${operation!}"/>
            <input class="form-control" id="id" name="id" type="hidden" value="${securityUser.id!}"/>
            <input class="form-control" id="roleIds" name="roleIds" type="hidden" value="${roleIds!}"/>
            <div class="form-group">
              <label class="col-sm-2 control-label">用户名称：</label>
              <div class="col-sm-8">
                <input class="form-control" id="username" name="username" required="required" type="text"
                       value="${securityUser.username!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">密码：</label>
              <div class="col-sm-8">
                <input class="form-control" id="password" name="password" required="required"
                       type="password" value="${securityUser.password!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">所属角色：</label>
              <div class="col-sm-8">
                <input class="form-control" id="roleNames" name="roleNames" readonly="readonly" required="required"
                       type="text" value="${roleNames!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
                <input class="btn btn-info" id="selectRole" onclick="UserMgr.selectRole()" type="button" value="选择"/>
              </div>
            </div>
            <div class="form-group">
              <@PageDict dict_name="status" dict_desc="状态" dict_key="user_status" dict_value="${securityUser.status!}"
              dict_type="radio" label_class="col-sm-2 control-label text-right" dict_class="col-sm-8"
              required="required" default_value="01"/>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">说明：</label>
              <div class="col-sm-8">
                <input class="form-control" id="comment" name="comment" required="required" type="text"
                       value="${securityUser.comment!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
</div>
<#include "/common/jslib.html">
<!-- 弹窗下拉 -->
<script type="text/javascript">
    function returnIndex() {
        window.location.href = "/securityUser/query";
    }

    $(function () {
        // 页面操作类型：add(添加)-edit(编辑)-view(查看)
        var operation = $("#operation").val();
        // 弹出窗体控制
        UserMgr = {
            // 初始化
            init: function () {
                // 查看的时候不显示保存按钮
                if (operation == "view") {
                    Jmts.setFormReadOnly();
                }
                initDict(DICTURL, FORM, operation);
            },
            // init end

            // 提交数据
            submitForm: function () {
                Jmts.ajaxSubmit(document.getElementById("userForm"), function (result) {
                    if (result.success) {
                        if (operation == 'add') {
                            UserMgr.returnIndex();
                        } else {
                            Jmts.succTips(result.msg);
                            window.location.reload();
                        }
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                });
                return false;
            },
            // submitForm end
            returnIndex: function () {
                window.location.href = "/securityUser/query";
            },
            selectRole: function () {
                var url = "/securityRole/to-selectRole?selectType=multiple&returnMethod=UserMgr.initRole";
                Jmts.openDialog("selectRole", url, "选择角色", 500, 600, 32);
            },
            initRole: function (selectStr) {
                var roles = selectStr.split(",");
                var ids = new StringBuilder("");
                var names = new StringBuilder("");
                var j = 0;
                for (var i in roles) {
                    var role = roles[i];
                    var roleInfo = role.split("#");
                    var id = roleInfo[0];
                    var name = roleInfo[1];
                    if (j == 0) {
                        ids.append(id);
                        names.append(name);
                    } else {
                        ids.append("," + id);
                        names.append("," + name);
                    }
                    j++;
                }
                $("#roleIds").val(ids.toString());
                $("#roleNames").val(names.toString());
            }
        };
        // 执行初始化
        UserMgr.init();
        // 前台验证表单
        $("#userForm").validate();
    });
</script>
</body>
</html>
